Skip to content

#12 AsyncRuntime 锁下状态机:竞争窗口与 coroutine 泄漏封死 - #28

Merged
benz-ai-x merged 2 commits into
mainfrom
fix/issue-12-async-runtime-races
Aug 20, 2026
Merged

#12 AsyncRuntime 锁下状态机:竞争窗口与 coroutine 泄漏封死#28
benz-ai-x merged 2 commits into
mainfrom
fix/issue-12-async-runtime-races

Conversation

@benz-ai-x

Copy link
Copy Markdown
Owner

摘要

  • STOPPED/STARTING/RUNNING/STOPPING/FAILED 状态机(锁下判定);start 只在上一代完整终止后发布新代,stop 超时 → start 拒绝且不建新线程
  • 每个 awaitable 恰好 await 或 close 一次(superseded 关闭 + finally 兜底;warnings-as-errors 测试)
  • generation 只清理自身;错误根因保留至下次成功 start
  • stop 各时相(factory 前/内/后、running 后)清理完整;20 轮压力零死锁
  • ProxyRuntime/SuanpanRuntime 接口不变(既有套件全绿)

验收对照

  • stop 超时 → start 失败不建新线程
  • stop 各时相清理
  • coroutine 显式 close;warnings-as-errors 无 RuntimeWarning
  • generation 只清理自身
  • 并发压力零死锁、零或一活线程
  • Proxy/Suanpan 接口兼容 + 回归
  • 错误保留至成功 start

pytest 1439;Closes #12

🤖 Generated with Claude Code

benz-ai-x and others added 2 commits August 20, 2026 15:32
- 状态机 STOPPED/STARTING/RUNNING/STOPPING/FAILED(锁下判定):start
  只在上一代完整终止后发布新代;stop 超时 → start 抛 RuntimeError 拒绝
  且不创建新线程(验收①)
- 每个 awaitable 恰好 await 或 close 一次:superseded 关闭 factory
  产物;任何异常路径 finally 兜底 close(验收③,warnings-as-errors 测)
- generation 只清理自身:loop/thread/stop_fn/error 均比对 generation
  才清(验收④)
- 错误根因保留至下次成功 start(FAILED 态不被 stop 覆盖)(验收⑦)
- stop 各时相清理:factory 前(stop_event 早退)、factory 内
  (superseded close)、返回后(stop_fn+close)、running 后(信号+join)
  (验收②)
- running 保留旧契约(stop_event 置位即 False);20 轮 start/stop
  压力零死锁零双活(验收⑤)
- ProxyRuntime/SuanpanRuntime 公开接口不变(既有套件全绿,两处 mock
  更新到状态机口径)(验收⑥)

pytest 1439 全绿。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
评审发现:connection_coordinator._start_proxy 与 app 的 sp.start 均为
裸调用无 try——start() 抛 RuntimeError 会冒上菜单/tick 崩溃。改为
返回 False + error 记录根因(不创建/不替换线程),生产零异常面。

pytest 38 相关绿。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@benz-ai-x
benz-ai-x merged commit 631cae2 into main Aug 20, 2026
0 of 4 checks passed
@benz-ai-x
benz-ai-x deleted the fix/issue-12-async-runtime-races branch August 20, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1][异步运行时] 关闭 stop/start 竞争窗口与 coroutine 泄漏

1 participant